package com.jy.dao.impl;

import com.jy.dao.ManageDao;
import com.jy.dao.UserDao;
import com.jy.entity.*;
import com.jy.util.DbUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

public class ManageDaoImpl implements ManageDao {
	QueryRunner runner=new QueryRunner();
	//登录
	@Override
	public Admin login(String name, String pass) throws Exception {
		Connection conn= DbUtil.getconn();
		String sql="select *from admin where aname=? and apass=?";
		Admin admin=runner.query(conn,sql,new BeanHandler<Admin>(Admin.class),name,pass);
		conn.close();
		return admin;
	}

	//注册
	@Override
	public int add(Admin obj) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="insert into admin(aname,apass,aphone) values(?,?,?)";
		Object[]p=new Object[3];
		p[0]=obj.aname;
		p[1]=obj.apass;
		p[2]=obj.aphone;
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	//找回
	@Override
	public Admin pwd(String name, String phone) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="select *from admin where aname=? and aphone=?";
		Admin admin=runner.query(conn,sql,new BeanHandler<Admin>(Admin.class),name,phone);
		conn.close();
		return admin;
	}

	//修改
	@Override
	public int update(Admin obj) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="update admin set apass=? where aname=?";
		Object[]p=new Object[2];
		p[0]=obj.apass;
		p[1]=obj.aname;
		int n= runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	@Override
	public List<Admin> getyh(String name) throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="select *from admin where aname=?";
		List<Admin> list=runner.query(conn, sql,new BeanListHandler<Admin>(Admin.class),name);
		conn.close();
		return list;
	}

	/**
	 * 查询考试记录的总条数
	 * @return
	 * @throws SQLException
	 */
	@Override
	public int logcount() throws SQLException {
		String se="select count(*) from exam_record";
		Connection conn= DbUtil.getconn();
		long in=runner.query(conn,se,new ScalarHandler<Long>());
		return (int)in;
	}

	/**
	 * 删除考试记录
	 * @param id  考试记录的ID
	 * @return
	 * @throws SQLException
	 */
	@Override
	public int detestlog(int id) throws SQLException {
		String se=" delete from exam_record where exam_record_id=?";
		Connection conn= DbUtil.getconn();
		int de=runner.update(conn,se,id);
		conn.close();
		return de;
	}

	/**
	 * 分页考试记录
	 * @param sat
	 * @param end
	 * @return
	 * @throws SQLException
	 */
	@Override
	public List findsell(int sat, int end) throws SQLException {
		String select="select * from telog limit ?,?";
		Connection conn= DbUtil.getconn();
		List lis=runner.query(conn,select,new BeanListHandler<Testlog>(Testlog.class),sat,end);
		return lis;
	}

	/**
	 *
	 * @param sat 起始值
	 * @param end 结束值
	 * @param name 姓名
	 * @return
	 * @throws SQLException
	 */
	@Override
	public List search(int sat,int end,String name) throws SQLException {
		String se=" select * from telog where stname like ? limit ?,?";
		String na="%"+name+"%";
		Connection conn= DbUtil.getconn();
		List lis=runner.query(conn,se,new BeanListHandler<Testlog>(Testlog.class),na,sat,end);
		return lis;
	}

	/**
	 * 统计搜索的总数
	 * @param name 搜索的name
	 * @return
	 * @throws SQLException
	 */
	@Override
	public int seacount(String name) throws SQLException {
		String se="select count(*) from telog where stname like ?";
		String na="%"+name+"%";
		Connection conn= DbUtil.getconn();
		long co=runner.query(conn,se,new ScalarHandler<Long>(),na);
		return (int)co;
	}

	//查询题目分类
	@Override
	public List<book> getbook(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<book> list=runner.query(conn, sql,new BeanListHandler<book>(book.class),objects);
		conn.close();
		return list;
	}


	//查询题目分类放入实体类
	@Override
	public book getbook2(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		book list=runner.query(conn, sql,new BeanHandler<book>(book.class),objects);
		conn.close();
		return list;
	}
	//查询学生id
	@Override
	public Student getstuid(String stname) throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="select *from student where stname=?";
		Student s=runner.query(conn, sql,new BeanHandler<>(Student.class),stname);
		conn.close();
		return s;
	}

	//分页查询考试
	@Override
	public List<ExamCenter> getexamcenter(int sat,int end) throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="SELECT e.exam_id,e.exam_name,e.exam_desc,e.exam_score,e.exam_time_limit,e.exam_start_date,e.exam_end_date,t.tname,e.create_time,e.exam_type,e.exam_zt,e.exam_classid FROM exam e,teacher t WHERE e.exam_creator_id=t.teacherId LIMIT ?,?";
		List<ExamCenter> list=runner.query(conn, sql,new BeanListHandler<ExamCenter>(ExamCenter.class),sat,end);
		conn.close();
		return list;
	}

	//模糊分页查询试卷
	@Override
	public List findexam_name(int sat,int end,String name) throws SQLException {
		String se=" select * from exam where exam_name like ? limit ?,?";
		String na="%"+name+"%";
		Connection conn= DbUtil.getconn();
		List lis=runner.query(conn,se,new BeanListHandler<ExamCenter>(ExamCenter.class),na,sat,end);
		return lis;
	}

	//删除试卷
	@Override
	public int delexam(int id) throws SQLException {
		String se=" delete from exam where exam_id=?";
		Connection conn= DbUtil.getconn();
		int de=runner.update(conn,se,id);
		conn.close();
		return de;
	}
	//分页查询教学视频
	@Override
	public List getstuvideo(String sql,Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<StuVideo> list=runner.query(conn, sql,new BeanListHandler<StuVideo>(StuVideo.class),objects);
		conn.close();
		return list;
	}
	//分页查询班级视频
	@Override
	public List getclsvideo(String sql,Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<ClsVideo> list=runner.query(conn, sql,new BeanListHandler<ClsVideo>(ClsVideo.class),objects);
		conn.close();
		return list;
	}
	//根据id删除视频
	@Override
	public int delvideo(int id) throws SQLException {
		String se=" delete from video where vid=?";
		Connection conn= DbUtil.getconn();
		int de=runner.update(conn,se,id);
		conn.close();
		return de;
	}
	//修改考试记录状态
	@Override
	public int updaterecord(int id) throws SQLException {
		String se="update exam_record set exam_zt='已下架' where exam_id=?";
		Connection conn= DbUtil.getconn();
		int de=runner.update(conn,se,id);
		conn.close();
		return de;
	}
	//添加考试
	@Override
	public int addtest(Timetest test) throws SQLException {
		String sql="insert into exam(exam_name,exam_avatar,exam_desc,exam_time_limit,exam_start_date,exam_end_date,exam_creator_id,create_time,exam_type,exam_zt,exam_classid) values(?,?,?,?,?,?,?,?,?,?,?)";
		Connection conn=DbUtil.getconn();
		Object p[]=new Object[11];
		p[0]=test.getExam_name();
		p[1]=test.getExam_avatar();
		p[2]=test.getExam_desc();
		p[3]=test.getExam_time_limit();
		p[4]=test.getExam_start_date();
		p[5]=test.getExam_end_date();
		p[6]=test.getExam_creator_id();
		p[7]=test.getCreate_time();
		p[8]=test.getExam_type();
		p[9]=test.getExam_zt();
		p[10]=test.getExam_classid();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}
	//修改考试
	@Override
	public int updatetest(Timetest t) throws SQLException {
		String sql="update exam set exam_question_ids=?,exam_score=?,exam_zt=? where exam_id=?";
		Connection conn=DbUtil.getconn();
		Object p[]=new Object[4];
		p[0]=t.getExam_question_ids();
		p[1]=t.getExam_score();
		p[2]=t.getExam_zt();
		p[3]=t.getExam_id();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}
	//实体类接收查询试卷
	@Override
	public Timetest getTimetest(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		Timetest time=runner.query(conn, sql,new BeanHandler<Timetest>(Timetest.class),objects);
		conn.close();
		return time;
	}
	@Override
	public List<Question> gettestquestion(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<Question> list=runner.query(conn, sql,new BeanListHandler<Question>(Question.class),objects);
		conn.close();
		return list;
	}
	//查询题目
	@Override
	public Question getquestion(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		Question q=runner.query(conn, sql,new BeanHandler<Question>(Question.class),objects);
		conn.close();
		return q;
	}
	//查询视频
	@Override
	public List<Video> getvideo(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<Video> list=runner.query(conn, sql,new BeanListHandler<Video>(Video.class),objects);
		conn.close();
		return list;
	}

	//添加视频
	@Override
	public int addvideo(Video t) throws SQLException {
		String sql="insert into video(vname,vdesc,vtype,vurl,classid,teacherid,vtime) values(?,?,?,?,?,?,?)";
		Connection conn=DbUtil.getconn();
		Object p[]=new Object[7];
		p[0]=t.getVname();
		p[1]=t.getVdesc();
		p[2]=t.getVtype();
		p[3]=t.getVurl();
		p[4]=t.getClassid();
		p[5]=t.getTeacherid();
		p[6]=t.getVtime();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}


	//添加错题
	@Override
	public int addfalsebook(FalseBook fb) throws SQLException {
		String sql="insert into falsebook(question_id,user_id,exam_id,user_answer,question_answera,question_answerb,question_answerc,question_answerd,question_answer,exam_type,question_name) values(?,?,?,?,?,?,?,?,?,?,?)";
		Connection conn=DbUtil.getconn();
		Object p[]=new Object[11];
		p[0]=fb.getQuestion_id();
		p[1]=fb.getUser_id();
		p[2]=fb.getExam_id();
		p[3]=fb.getUser_answer();
		p[4]=fb.getQuestion_answera();
		p[5]=fb.getQuestion_answerb();
		p[6]=fb.getQuestion_answerc();
		p[7]=fb.getQuestion_answerd();
		p[8]=fb.getQuestion_answer();
		p[9]=fb.getExam_type();
		p[10]=fb.getQuestion_name();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}
	//查询错题本
	@Override
	public List falsebook(String sql,Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List lis=runner.query(conn,sql,new BeanListHandler<FalseBook>(FalseBook.class),objects);
		conn.close();
		return lis;
	}

	//获取学生数
	@Override
	public int getstucount(String sql,Object... objects) throws SQLException{
		Connection conn=DbUtil.getconn();
		long n=runner.query(conn,sql,new ScalarHandler<>(),objects);
		return  (int)n;
	}

	//根据试卷id进行分数排名
	@Override
	public List orderbyscore(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<OrderByScore> list=runner.query(conn, sql,new BeanListHandler<OrderByScore>(OrderByScore.class),objects);
		conn.close();
		return list;
	}
	//根据错题本中题目出现的次数进行错题排名
	@Override
	public List orderbyfalse(String sql, Object... objects) throws SQLException {
		Connection conn= DbUtil.getconn();
		List<OrderByFalse> list=runner.query(conn, sql,new BeanListHandler<OrderByFalse>(OrderByFalse.class),objects);
		conn.close();
		return list;
	}
	//考试情况:查询所有班级
	@Override
	public List cxsybj() throws SQLException {

		Connection conn= DbUtil.getconn();
		String sql="select * from classes ";
		List list=runner.query(conn, sql,new BeanListHandler<Classes>(Classes.class));
		conn.close();
		return list;
	}
	//考试情况:查询所有试卷
	@Override
	public List<exam_record> cxsysj() throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="select exam_name from exam";
		List<exam_record> list=runner.query(conn, sql,new BeanListHandler<exam_record>(exam_record.class));
		conn.close();
		return list;
	}

	//考试情况:班级查询考试情况
	@Override
	public List cxksbj(String sql/*,int limit, int size,Object... param*/) throws SQLException {
		Connection conn= DbUtil.getconn();
		/*sql+=" limit "+(limit-1)*size+","+size;*/
		List list=runner.query(conn,sql,new BeanListHandler<exam_record>(exam_record.class));
		conn.close();
		return list;
	}
	//考试情况:试卷查询考试情况
	@Override
	public List<exam_record> cxkssj(String exam_name) throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="select *from myksjl where exam_name=?";
		List<exam_record> list=runner.query(conn, sql,new BeanListHandler<exam_record>(exam_record.class),exam_name);
		conn.close();
		return list;
	}
	//考试情况:删除
	@Override
	public int delsj(int exam_record_id) throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="DELETE FROM exam_record WHERE exam_record_id=?";
		int n=runner.update(conn,sql,exam_record_id);
		conn.close();
		return n;
	}
	//考试情况查行数
	public int getCount(String sql,Object... param) throws Exception {
		Connection conn=DbUtil.getconn();
		long n=runner.query(conn,sql,new ScalarHandler<Long>(),param);
		conn.close();
		return (int)n;
	}

	@Override
	public List getPage(int p)throws Exception{
		int n=(p-1)*7;
		String sql="select *from teacher "+"limit ?,7";
		Connection conn=DbUtil.getconn();
		List list=runner.query(conn,sql,new BeanListHandler<Teacher>(Teacher.class),n);
		conn.close();
		return list;
	}

	//查行数
	@Override
	public int count() throws Exception {
		String sql="select count(*) from teacher";
		Connection conn=DbUtil.getconn();
		long n=runner.query(conn,sql,new ScalarHandler<Long>());
		conn.close();
		return (int)n;
	}

	//查询
	@Override
	public List find(String tname) throws Exception {
		String sql="select *from teacher where tname like ?";
		String p="%"+ tname +"%";
		Connection conn=DbUtil.getconn();
		List list=runner.query(conn,sql,new BeanListHandler<Teacher>(Teacher.class),p);
		conn.close();
		return list;
	}

	//查询
	@Override
	public List find2(String job) throws Exception {
		String sql="select *from teacher where tjob like ?";
		String p="%"+ job +"%";
		Connection conn=DbUtil.getconn();
		List list=runner.query(conn,sql,new BeanListHandler<Teacher>(Teacher.class),p);
		conn.close();
		return list;
	}

	@Override
	public int delete(Teacher obj) throws Exception {
		String sql="delete from teacher where tname=?";
		Connection conn=DbUtil.getconn();
		Object p[]=new Object[1];
		p[0]=obj.getTname();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	@Override
	public int add(Teacher obj) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="insert into teacher(tname,tpass,tphone,tjob) values(?,?,?,?)";
		Object p[]=new Object[4];
		p[0]=obj.getTname();
		p[1]=obj.getTpass();
		p[2]=obj.getTphone();
		p[3]=obj.getTjob();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	//修改
	@Override
	public int update(Teacher obj) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="update teacher set tname=?,tpass=?,tphone=?,tjob=? where teacherId=?";
		Object p[]=new Object[5];
		p[0]=obj.getTname();
		p[1]=obj.getTpass();
		p[2]=obj.getTphone();
		p[3]=obj.getTjob();
		p[4]=obj.getTeacherId();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	@Override
	public List<Teacher> getls(String name) throws SQLException {
		Connection conn=DbUtil.getconn();
		String sql="select *from teacher where tname=?";
		List<Teacher> list=runner.query(conn, sql,new BeanListHandler<Teacher>(Teacher.class),name);
		conn.close();
		return list;
	}

	/**
	 * 删除评论
	 * @param cid
	 * @return
	 */
	@Override
	public int delcomment(String cid) {
		Connection conn = DbUtil.getconn();
		String sql = "delete from comment where cid in("+cid+");";
		int i=0;
		try {
			i = runner.update(conn,sql);
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}

	/**
	 * 分页模糊查询评论表用户
	 * @param page
	 * @param limit
	 * @param uname
	 * @return
	 */
	@Override
	public List queryall(int page, int limit,String uname) {
		Connection conn = DbUtil.getconn();
		String sql = "select * from comment where uid in(select stid  from student where stname like '%"+uname+"%') limit ?,?;";
		List list = null;
		int index = (page-1)*limit;
		try {
			list  = runner.query(conn,sql,new BeanListHandler<Comment>(Comment.class),index,limit);
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public List findquestionspage(String sql,Object... objects) {
		Connection conn = DbUtil.getconn();
		List list=null;
		try {
		list  = runner.query(conn,sql,new BeanListHandler<QuestionsPage>(QuestionsPage.class),objects);
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	//根据id删除视频
	@Override
	public int delquestion(int id) throws SQLException {
		String se=" delete from question where question_id=?";
		Connection conn= DbUtil.getconn();
		int de=runner.update(conn,se,id);
		conn.close();
		return de;
	}

	/**
	 * 统计模糊查询评论表数量
	 * @param uname
	 * @return
	 */
	@Override
	public int getcount(String uname) {
		Connection conn = DbUtil.getconn();
		String sql = "select count(*) from comment where uid in(select stid  from student where stname like '%"+uname+"%');";
		long lo= 0;
		try {
			lo = runner.query(conn,sql,new ScalarHandler<Long>());
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return (int)lo;
	}


	/**
	 * 根据评论表删除留言
	 * @param cid
	 * @return
	 */
	@Override
	public int delreqly(String cid) {
		Connection conn = DbUtil.getconn();
		String sql = "delete from reply where cid in("+cid+");";
		int i=0;
		try {
			i = runner.update(conn,sql);
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}

	@Override
	public int addquestion(Question question) throws Exception {
		Connection conn = DbUtil.getconn();
		String sql = "insert into question(question_name,question_score,question_creator,question_type,question_optiona," +
				"question_optionb,question_optionc," +
				"question_optiond,question_answer,update_time,question_bookid) values(?,?,?,?,?,?,?,?,?,?,?)";
		Object []o = new Object[11];
		o[0] = question.question_name;
		o[1] = question.question_score;
		o[2] = question.question_creator;
		o[3] = question.question_type;
		o[4] = question.question_optiona;
		o[5] = question.question_optionb;
		o[6] = question.question_optionc;
		o[7] = question.question_optiond;
		o[8] = question.question_answer;
		o[9] = question.update_time;
		o[10] = question.question_bookid;
		int n = runner.update(conn,sql,o);
		conn.close();
		return n;
	}

	@Override
	public List getbookid(String bookname) throws Exception {
		Connection conn = DbUtil.getconn();
		String sql = "select distinct book_id from book where book_name=?";
		List list = runner.query(conn,sql,new ColumnListHandler<String>("book_id"),bookname);//封装某个数据的一列
		conn.close();
		return list;
	}

	//修改老师注册码
	@Override
	public int lszcmpdate(register obj) throws Exception {
		Connection conn= DbUtil.getconn();
		String sql="UPDATE register SET zcm_tea=? WHERE rid=?";
		Object p[]=new Object[2];
		p[0]=obj.getZcm_tea();
		p[1]=obj.getRid();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}
	//修改学生注册码
	@Override
	public int xszcmpdate(register obj) throws Exception {
		Connection conn= DbUtil.getconn();
		String sql="UPDATE register SET zcm_stu=? WHERE rid=?";
		Object p[]=new Object[2];
		p[0]=obj.getZcm_stu();
		p[1]=obj.getRid();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}



	//查询
	@Override
	public List getstuPage(int p) throws Exception {
		int n=(p-1)*7;
		String sql="select *from student "+"limit ?,7";
		Connection conn= DbUtil.getconn();
		List list=runner.query(conn,sql,new BeanListHandler<Student>(Student.class),n);
		conn.close();
		return list;
	}

	//查行数
	@Override
	public int stucount() throws Exception {
		String sql="select count(*) from student";
		Connection conn=DbUtil.getconn();
		long n=runner.query(conn,sql,new ScalarHandler<Long>());
		conn.close();
		return (int)n;
	}

	//模糊查询name
	@Override
	public List findstu(String stname) throws Exception {
		String sql="select *from student where stname like ?";
		String p="%"+ stname +"%";
		Connection conn=DbUtil.getconn();
		List list=runner.query(conn,sql,new BeanListHandler<Student>(Student.class),p);
		conn.close();
		return list;
	}

	//删除
	@Override
	public int deletestu(Student obj) throws Exception {
		String sql="delete from student where stname=?";
		Connection conn=DbUtil.getconn();
		Object p[]=new Object[1];
		p[0]=obj.getStname();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	@Override
	public int addstu(Student obj) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="insert into student(classid,stname,stpass,stphone,stsex,stwx) values(?,?,?,?,?,?)";
		Object p[]=new Object[6];
		p[0]=obj.getClassid();
		p[1]=obj.getStname();
		p[2]=obj.getStpass();
		p[3]=obj.getStphone();
		p[4]=obj.getStsex();
		p[5]=obj.getStwx();
		//p[6]=obj.stavatar;
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	//修改
	@Override
	public int updatestu(Student obj) throws Exception {
		Connection conn=DbUtil.getconn();
		String sql="update student set classid=?,stname=?,stpass=?,stphone=?,stsex=?,stwx=? where stid=?";
		Object p[]=new Object[7];
		p[0]=obj.getClassid();
		p[1]=obj.getStname();
		p[2]=obj.getStpass();
		p[3]=obj.getStphone();
		p[4]=obj.getStsex();
		p[5]=obj.getStwx();
		p[6]=obj.getStid();
		int n=runner.update(conn,sql,p);
		conn.close();
		return n;
	}

	//查询是否有该学生
	@Override
	public List<Student> getstu(String name) throws SQLException {
		Connection conn=DbUtil.getconn();
		String sql="select *from student where stname=?";
		List<Student> list=runner.query(conn, sql,new BeanListHandler<Student>(Student.class),name);
		conn.close();
		return list;
	}
	//寻找学生
	@Override
	public List<Student> findstu2(String stname) throws SQLException {
		Connection conn= DbUtil.getconn();
		String sql="select *from student where stname=?";
		List<Student> list=runner.query(conn, sql,new BeanListHandler<Student>(Student.class),stname);
		conn.close();
		return list;
	}


	/**
	 * 修改班级考试
	 * @param
	 * @param ts 考试实体类
	 * @return
	 * @throws SQLException
	 */

	@Override
	public int upexam(Timetest ts) throws SQLException {
		String upex="update exam set exam_name=?,exam_desc=?,exam_time_limit=?,exam_classid=? where exam_id=?";
		Connection conn= DbUtil.getconn();
		Object obj[]=new Object[5];
		obj[0]=ts.getExam_name();
		obj[1]=ts.getExam_desc();
		obj[2]=ts.getExam_time_limit();
		obj[3]=ts.getExam_classid();
		obj[4]=ts.getExam_id();
		int up=runner.update(conn,upex,obj);
		return up;
	}

	@Override
	public int uptimeexam(Timetest ts) throws SQLException {
		String upex="update exam set exam_name=?,exam_desc=?,exam_time_limit=?,exam_start_date=?,exam_end_date=? where exam_id=?";
		Connection conn= DbUtil.getconn();
		Object obj[]=new Object[6];
		obj[0]=ts.getExam_name();
		obj[1]=ts.getExam_desc();
		obj[2]=ts.getExam_time_limit();
		obj[3]=ts.getExam_start_date();
		obj[4]=ts.getExam_end_date();
		obj[5]=ts.getExam_id();
		int up=runner.update(conn,upex,obj);
		return up;
	}
	@Override
	public int upgdexam(Timetest ts) throws SQLException {
		String upex="update exam set exam_name=?,exam_desc=?,exam_time_limit=? where exam_id=?";
		Connection conn= DbUtil.getconn();
		Object obj[]=new Object[4];
		obj[0]=ts.getExam_name();
		obj[1]=ts.getExam_desc();
		obj[2]=ts.getExam_time_limit();
		obj[3]=ts.getExam_id();
		int up=runner.update(conn,upex,obj);
		return up;
	}

	@Override
	public int upquestion(Question q) throws SQLException {
		String upex="update question set question_name=?,question_score=?,question_answer=?,question_bookid=? where question_id=?";
		Connection conn= DbUtil.getconn();
		Object obj[]=new Object[5];
		obj[0]=q.getQuestion_name();
		obj[1]=q.getQuestion_score();
		obj[2]=q.getQuestion_answer();
		obj[3]=q.getQuestion_bookid();
		obj[4]=q.getQuestion_id();
		int up=runner.update(conn,upex,obj);
		return up;
	}


}
